package leetcode.code0970;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

import leetcode.IDebug;

public class Solution implements IDebug {

	public List<Integer> powerfulIntegers(int x, int y, int bound) {
		Set<Integer> ans = new HashSet<>();
		int m = x == 1 ? 0 : (int) (Math.log10(bound) / Math.log10(x));
		int n = y == 1 ? 0 : (int) (Math.log10(bound) / Math.log10(y));
		for (int i = 0; i <= m; i++) {
			for (int j = 0; j <= n; j++) {
				int cur = (int) Math.pow(x, i) + (int) Math.pow(y, j);
				if (cur <= bound) {
					ans.add(cur);
				}
			}
		}
		return new ArrayList<>(ans);
	}

	private void f(int x, int y, int bound, List<Integer> ans, int i, int j) {
		int cur = (int) Math.pow(x, i) + (int) Math.pow(y, j);
		if (cur <= bound) {
			ans.add(cur);
			this.f(x, y, bound, ans, i + 1, j);
			this.f(x, y, bound, ans, i, j + 1);
			this.f(x, y, bound, ans, i + 1, j + 1);
		}
	}

	@Override
	public void debug1() {
		// TODO Auto-generated method stub

	}

	@Override
	public void debug2() {
		// TODO Auto-generated method stub

	}

	@Override
	public void debug3() {
		// TODO Auto-generated method stub

	}

	@Override
	public void debug4() {
		// TODO Auto-generated method stub

	}

	public static void main(String[] args) {
		Solution so = new Solution();
		so.debug1();
		so.debug2();
		so.debug3();
		so.debug4();
//		so.powerfulIntegers(2, 3, 10);
		so.powerfulIntegers(2, 1, 10);
//		System.out.println(Math.log10(10));
	}

}
